package com.lsh.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/12/17 3:08 下午
 * @desc ：创建一个单线程化的线程池，它只会用唯一的工作线程来执行任务，保证所有任务按照指定顺序(FIFO, LIFO, 优先级)执行。
 * 结果依次输出，相当于顺序执行各个任务。当shutdown时停止线程
 */
public class NewSingleThreadExecutor {
    public static void main(String[] args) {
        //1.创建单线程
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 10 ; i++) {
            int finalI = i;
            executorService.execute(() ->{
                System.out.println(finalI);
            });

        }
        executorService.shutdown();
    }
}
